import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_app/utils/windowUtil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:flutter_app/widget/AppBarTemp1.dart';

//import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter/services.dart';
//import 'package:barcode_scan/barcode_scan.dart';
import 'package:flutter_app/bean/Shop1.dart';
import 'ShopDetail.dart';
//import 'package:qr_reader/qr_reader.dart';
//import 'package:qrscan/qrscan.dart' as scanner;

//import 'package:fast_qr_reader_view/fast_qr_reader_view.dart';

class HomeWidget1 extends StatefulWidget {
  @override
  State<HomeWidget1> createState() => _HomeWidget1State();
}

class _HomeWidget1State extends State<HomeWidget1> {
  int _itemCount;

  bool _loop;

  bool _autoplay;

  int _autoplayDely;

  double _padding;

  bool _outer;

  double _radius;

  double _viewportFraction;

  SwiperLayout _layout;

  int _currentIndex;

  double _scale;

  Axis _scrollDirection;

  Curve _curve;

  double _fade;

  bool _autoplayDisableOnInteraction;

  CustomLayoutOption customLayoutOption;

  SwiperController _controller;

  var titles;
  var writers;
  var content;
  String barcode = "";
  String result = "";
//  List<CameraDescription> cameras;
//  QRReaderController controller;
  List<String> c = ["美食", '娱乐', "酒店", '家居', '服饰', '培训', '旅游', '丽人', '健康', '其他'];
  List<String> image = ["images/banner1.png", "images/banner2.png"];
  FocusNode focusNode = new FocusNode();
  int index = 0;

  int itemclicked = 0;
  Future<String> _barcodeString;
  List<Shop1> shoplist;
  @override
  void initState() {
    super.initState();
//    Future<String> futureString = new QRCodeReader()
//        .setAutoFocusIntervalInMs(200) // default 5000
//        .setForceAutoFocus(true) // default false
//        .setTorchEnabled(true) // default false
//        .setHandlePermissions(true) // default true
//        .setExecuteAfterPermissionGranted(true) // default true
//        .scan();
    customLayoutOption = new CustomLayoutOption(startIndex: -1, stateCount: 3)
        .addRotate([-25.0 / 180, 0.0, 25.0 / 180]).addTranslate([
      new Offset(-350.0, 0.0),
      new Offset(0.0, 0.0),
      new Offset(350.0, 0.0)
    ]);
    _fade = 1.0;
    _currentIndex = 0;
    _curve = Curves.ease;
    _scale = 0.5;
    //  _scale = 0.5;
    _controller = new SwiperController();
    _layout = SwiperLayout.DEFAULT;
    _radius = 10.0;
    _padding = 0.0;
    _loop = true;
    _itemCount = 5;
    _autoplay = false;
    _autoplayDely = 3000;
    _viewportFraction = 0.2;
    _outer = false;
    _scrollDirection = Axis.horizontal;
    _autoplayDisableOnInteraction = false;
    //  compute(testisolate,null);

//    main();
//    controller = new QRReaderController(cameras[0], ResolutionPreset.medium, [CodeFormat.qr], (dynamic value){
//      print(value); // the result!
//      // ... do something
//      // wait 3 seconds then start scanning again.
//      new Future.delayed(const Duration(seconds: 3), controller.startScanning);
//    });
//    controller.initialize().then((_) {
//      if (!mounted) {
//        return;
//      }
//      setState(() {});
//      controller.startScanning();
//    });
    createlist();
  }

//  Future<Null> main() async {
//    cameras = await availableCameras();
//
//  }
  @override
  Widget build(BuildContext context) {
    return Material(
      child: new Stack(
        children: <Widget>[
          CustomScrollView(
            slivers: <Widget>[
              SliverToBoxAdapter(
                child: Container(
                  child: Column(
                    children: <Widget>[
                      topBanner(),
                      Container(
                        child: Column(
//              physics: NeverScrollableScrollPhysics(),
                          children: <Widget>[
                            Container(
                              child: GridView.count(
                                crossAxisCount: 5,
                                children: c.map((s) {
                                  return getGridviewItem(s);
                                }).toList(),
                                shrinkWrap: true,
                                childAspectRatio: windowUtil.width / 5 / 60,
                                physics: NeverScrollableScrollPhysics(),
                              ),
                            ),
                            SizedBox(height: 10.0),
                            notification(),
                            banner1(),
                            Container(
                              margin: EdgeInsets.only(left: 10.0, right: 10.0),
                              height: 110.0,
                              child: new Swiper(
                                itemBuilder: (BuildContext context, int index) {
                                  return new Container(
                                    margin: EdgeInsets.only(left: 10.0,right: 10.0),
                                    child:
                                  new Image.asset(image[index],
                                      fit: BoxFit.fill,
                                      height:
                                      MediaQuery.of(context).size.height *
                                          0.2)

                                    ,);

                                },
                                itemCount: image.length,
                                viewportFraction: 0.8,
                                autoplay: true,
                                onIndexChanged: (int s) {
                                  index = s;
                                  setState(() {});
                                },
                                pagination:
////          new SwiperPagination(builder: SwiperPagination.fraction),
                                    new SwiperPagination(
                                        builder: DotSwiperPaginationBuilder(
                                  color: Colors.black54,
                                  activeColor: Colors.white,
                                )),
                              ),
                            ),
                          ],
                        ),
                      ), //banner
                      ptjx(),
                      cxbp(),
                      list(),
                    ],
                  ),
                ),
              ),
              SliverList(
                  delegate: SliverChildBuilderDelegate(
                          ( context, index) {
                        return buildItem(context, index);
                      },

                      childCount: shoplist.length),
                   )
            ],
          ),
        ],
      ),

//      floatingActionButton: FloatingActionButton(onPressed: null,child: Image.asset("images/ex3.png",width: 50.0,height: 50.0,fit: BoxFit.contain,),
//        backgroundColor:Colors.transparent,elevation: 0.0,
//        highlightElevation: 0.0,
//      ),
    );
  }

  Widget getGridviewItem(String s) {
//    List<Widget> list=List();
//    for(int i=0;i<10;i++){
//      list.add(
//          Container(child: Image.asset("images/img.jpg",width: 30.0,height: 30.0)),)
//          ;
//    }
//
//    return list;

    return GestureDetector(
      child: Column(
        //crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Image.asset(
            "images/hotel.png",
            width: 30.0,
            height: 30.0,
          ),
          SizedBox(height: 5.0),
          Text(
            s,
            style: TextStyle(color: Color(0xff000000), fontSize: 12.0),
            maxLines: 1,
          )
        ],
      ),
      onTap: () {
        print(s);
      },
    );
  }

  Widget buildSwiper() {
    return new Swiper(
      onTap: (int index) {
        print(">>>>>>>>>>>>>>>>>>>>");
//        Fluttertoast.showToast(msg: " is clicked");
//        Navigator
//            .of(context)
//            .push(new MaterialPageRoute(builder: (BuildContext context) {
//          return Scaffold(
//            appBar: AppBar(
//              title: Text("New page"),
//            ),
//            body: Container(),
//          );
//        }));
      },
      customLayoutOption: customLayoutOption,
      fade: _fade,
      index: _currentIndex,
      onIndexChanged: (int index) {
        setState(() {
          _currentIndex = index;
        });
      },
      curve: _curve,
      scale: _scale,
      itemWidth: 100.0,
      // itemWidth: 100.0,
      controller: _controller,
      layout: _layout,
      outer: _outer,
      itemHeight: 50.0,
      viewportFraction: _viewportFraction,
      autoplayDelay: _autoplayDely,
      loop: _loop,
      autoplay: _autoplay,
      itemBuilder: _buildItem,
      itemCount: _itemCount,
      scrollDirection: _scrollDirection,
      autoplayDisableOnInteraction: _autoplayDisableOnInteraction,
      pagination: new SwiperPagination(),
    );
  }

  Widget _buildItem(BuildContext context, int index) {
    return new GestureDetector(
      onTap: () {
        print(">>>>>>>>>>>>>>>>>>>>> $index");
      },
      child: ClipRRect(
        borderRadius: new BorderRadius.all(new Radius.circular(_radius)),
        child: new Image.asset(
          "images/img.jpg",
          fit: BoxFit.fill,
        ),
      ),
    );
  }

  Widget gridview() {
    return GridView.count(
      crossAxisCount: 2,
      children: item(),
      shrinkWrap: true,
      physics: NeverScrollableScrollPhysics(),
      padding: EdgeInsets.all(5.0),
      mainAxisSpacing: 5.0,
      crossAxisSpacing: 5.0,
    );
  }

  List<Widget> item() {
    List<Widget> w = List();
    for (int i = 0; i < 4; i++) {
      w.add(new Container(
        width: (windowUtil.width - 30) / 2,
        height: (windowUtil.width - 30) / 2,
        decoration: BoxDecoration(
            color: Color(0xffF0FFF0), borderRadius: BorderRadius.circular(2.0)),
        child: Column(
          children: <Widget>[
            Text(
              "精选",
              style: TextStyle(
                  color: Color(0xff000000),
                  fontWeight: FontWeight.bold,
                  fontSize: 16.0),
            ),
            SizedBox(
              height: 10.0,
            ),
            Image.asset(
              "images/ex3.png",
              width: 100.0,
              height: 100.0,
              fit: BoxFit.fitHeight,
            ),
            Container(
              decoration: BoxDecoration(
                  color: Color(0xffFDF5E6),
                  border: Border.all(color: Colors.red),
                  borderRadius: BorderRadius.circular(2.0)),
              child: Text(
                "实惠好货",
                style: TextStyle(
                  color: Colors.red,
                ),
              ),
            )
          ],
        ),
      ));
    }
    return w;
  }

  Widget statusbar() {
    return Container(
      margin: EdgeInsets.only(top: windowUtil.statusbar),
      child: Row(children: <Widget>[
        Text(
          "上海市",
          style: TextStyle(color: Color(0xffffffff), fontSize: 19.0),
        ),
        Expanded(child: Text("")),
        Center(
            child: Container(
                height: 30.0,
                width: 150.0,
                decoration: BoxDecoration(
                    border: Border.all(color: Color(0xffffffff),width: 1.0),
                    borderRadius: BorderRadius.circular(15.0)

                ),
                 child:Row(children: <Widget>[
                   Container(
                     width: 120.0,
                     height: 30.0,
                     child:TextField(
                       style: TextStyle(color: Color(0xffffffff)),
                       focusNode: focusNode,
                       onTap: () {
                         FocusScope.of(context).requestFocus(focusNode);
                       },
                       enabled: true,
                       onSubmitted: (s) {
                         print("finish");
                       },
                       textInputAction: TextInputAction.go,
                       decoration: InputDecoration(
                         contentPadding: EdgeInsets.only(left: 10.0, top: 5.0),
                         hintText: "搜索商品",
                         hintStyle: TextStyle(
                           color: Color(0xffffffff),
                         ),
                         labelStyle: TextStyle(color: Color(0xffffffff)),
                          
//                     enabledBorder: OutlineInputBorder(
//                       /*边角*/
//                       borderRadius: BorderRadius.all(
//                         Radius.circular(30), //边角为30
//                       ),
//                       borderSide: BorderSide(
//                         color: Colors.white, //边线颜色为黄色
//                         width: 2, //边线宽度为2
//                       ),
//                     ),
//                     focusedBorder: OutlineInputBorder(
//                         borderRadius: BorderRadius.all(
//                           Radius.circular(30), //边角为30
//                         ),
//                         borderSide: BorderSide(
//                           color: Colors.white, //边框颜色为绿色
//                           width: 2, //宽度为5
//                         )),
                         border: InputBorder.none,
                         // errorText: "errorText",


                         hasFloatingPlaceholder: false,
                       ),
                     ),
                   ),

                 Image.asset("images/search.png",width: 20.0,height: 20.0,)
                 ],),
                 )),
        Expanded(child: Text("")),
        Container(
          width: 50.0,
          height: 50.0,
          child:
          GestureDetector(child: Image.asset(
            "images/scan.png",
            width: 30.0,
            height: 30.0,
          ),
          onTap: (){

//            _barcodeString = new QRCodeReader()
//                .setAutoFocusIntervalInMs(200)
//                .setForceAutoFocus(true)
//                .setTorchEnabled(true)
//                .setHandlePermissions(true)
//                .setExecuteAfterPermissionGranted(true)
//                .scan();
//
//
//             _barcodeString.then((s){
//               Fluttertoast.showToast(msg: '扫到的内容是$s',toastLength: Toast.LENGTH_LONG);
//
//
//             });
          },
          ),

          padding: EdgeInsets.all(10.0),
        )
      ]),
    );
  }

  Widget topBanner() {
//    return Image.asset("images/banner.png",width: windowUtil.width,height: 180.0,fit: BoxFit.fill,);
    return Stack(
      children: <Widget>[
        GestureDetector(
          child: Image.asset(
            "images/banner.png",
            width: windowUtil.width,
            height: 180.0,
            fit: BoxFit.fill,
          ),
          onTap: () {
//      _scanQR();
            scan();
//            Fluttertoast.showToast(msg: "购物车");
          },
        ),
        statusbar(),
      ],
    );
  }

  scan() async {
//    String barcode = await scanner.scan();
  }
  Widget notification() {
    return Container(
        margin: EdgeInsets.only(left: 10.0),
        height: 30.0,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Image.asset(
              "images/xianbao.png",
              width: 60.0,
              height: 25.0,
            ),
            Expanded(
              child: Container(
                  padding: EdgeInsets.only(top: 5.0, left: 10.0),
                  child: Swiper(
                    itemBuilder: (_, index) {
                      return Text(
                        "东北大米XBbos联合活动，限时开启",
                        style: TextStyle(fontSize: 16.0),
                      );
                    },
                    itemCount: 3,
                    autoplay: true,

//
                    scrollDirection: Axis.vertical,
                  )),
            ),

//        Container(
//          width: 100.0,
//          height: 50.0,
//          child: ,),
          ],
        ));
  }

//  Future scan() async {
//    try {
//      String barcode = await BarcodeScanner.scan();
//      setState(() {
//        return this.barcode = barcode;
//      });
//    } on PlatformException  catch (e) {
//      if (e.code == BarcodeScanner.CameraAccessDenied) {
//        setState(() {
//          return this.barcode = 'The user did not grant the camera permission!';
//        });
//      } else {
//        setState(() {
//          return this.barcode = 'Unknown error: $e';
//        });
//      }
//    } on FormatException{
//      setState(() => this.barcode = 'null (User returned using the "back"-button before scanning anything. Result)');
//    } catch (e) {
//      setState(() => this.barcode = 'Unknown error: $e');
//    }
//  }

//  Future _scanQR() async {
//    try {
//      String qrResult = await BarcodeScanner.scan();
//      setState(() {
//        result = qrResult;
//      });
//    } on PlatformException catch (ex) {
//      if (ex.code == BarcodeScanner.CameraAccessDenied) {
//        print("denied");
//        Fluttertoast.showToast(msg: "1");
//        setState(() {
//          result = "Camera permission was denied";
//        });
//      } else {
//        Fluttertoast.showToast(msg: "2");
//        print("exception");
//        setState(() {
//          result = "Unknown Error $ex";
//        });
//      }
//    } on FormatException {
//      Fluttertoast.showToast(msg: "3");
//      print("1");
//      setState(() {
//        result = "You pressed the back button before scanning anything";
//      });
//    } catch (ex) {
//      Fluttertoast.showToast(msg: "4");
//      print("2");
//      setState(() {
//        result = "Unknown Error $ex";
//      });
//    }
//  }

  Widget banner1() {
    return Row(
      children: <Widget>[
        SizedBox(
          width: 10.0,
        ),
        Expanded(
            child: Image.asset(
          "images/mingxing.png",
          height: 90.0,
        )),
        SizedBox(
          width: 10.0,
        ),
        Expanded(
            child: Image.asset(
          "images/chaozhi.png",
          height: 90.0,
        )),
        SizedBox(
          width: 10.0,
        ),
        Expanded(
            child: Image.asset(
          "images/xianshi.png",
          height: 90.0,
        )),
        SizedBox(
          width: 10.0,
        ),
        Expanded(
            child: Image.asset(
          "images/qiandao.png",
          height: 90.0,
        )),
        SizedBox(
          width: 10.0,
        )
      ],
    );
  }

  Widget ptjx() {
    return Container(
      margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 10.0),
      child: Column(
        children: <Widget>[
          Row(
            crossAxisAlignment: CrossAxisAlignment.end,
            children: <Widget>[
              Text(
                "平台精选",
                style: TextStyle(
                    color: Color(0xff040404),
                    fontSize: 21.0,
                    fontWeight: FontWeight.bold),
              ),
              Text(
                "    每一个都给你惊喜",
                style: TextStyle(color: Color(0xffededed)),
              )
            ],
          ),
          SizedBox(
            height: 10.0,
          ),
          Row(
            children: <Widget>[
              Expanded(
                child: Container(
                  child: Stack(
                    children: <Widget>[
                      Positioned(
                        child: Image.asset(
                          "images/meirishangxin.png",
                          width: 30.0,
                          height: 30.0,
                          fit: BoxFit.fill,
                        ),
                        left: 10.0,
                        top: 10.0,
                      ),
                      Positioned(
                        child: Text("每日上新"),
                        left: 45.0,
                        top: 15.0,
                      ),
                      Positioned(
                        child: Image.asset(
                          "images/ex1.png",
                          width: windowUtil.width / 5.0,
                          height: 90.0,
                          fit: BoxFit.fitHeight,
                        ),
                        left: 10.0,
                        top: 50.0,
                      ),
                      Positioned(
                        child: Image.asset("images/ex2.png",
                            width: windowUtil.width / 5.0,
                            height: 90.0,
                            fit: BoxFit.fitHeight),
                        left: windowUtil.width / 5.0 + 10.0,
                        top: 50.0,
                      ),
                    ],
                  ),
                  height: 150.0,
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage(
                            "images/bgleft.png",
                          ),
                          fit: BoxFit.fill)),
                ),
              ),
              Expanded(
                  child: Container(
                child: Stack(
                  children: <Widget>[
                    Positioned(
                      child: Image.asset(
                        "images/rexiaojianhuo.png",
                        width: 30.0,
                        height: 30.0,
                        fit: BoxFit.fill,
                      ),
                      left: 10.0,
                      top: 10.0,
                    ),
                    Positioned(
                      child: Text("热销尖货"),
                      left: 45.0,
                      top: 15.0,
                    ),
                    Positioned(
                      child: Image.asset(
                        "images/ex1.png",
                        width: windowUtil.width / 5.0,
                        height: 90.0,
                        fit: BoxFit.fitHeight,
                      ),
                      left: 10.0,
                      top: 50.0,
                    ),
                    Positioned(
                      child: Image.asset("images/ex2.png",
                          width: windowUtil.width / 5.0,
                          height: 90.0,
                          fit: BoxFit.fitHeight),
                      left: windowUtil.width / 5.0 + 10.0,
                      top: 50.0,
                    ),
                  ],
                ),
                height: 150.0,
                decoration: BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage("images/bgright.png"),
                        fit: BoxFit.fill)),
              ))
            ],
          )
        ],
      ),
    );
  }

  Widget cxbp() {
    return Container(
        margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 10.0),
        child: Column(
          children: <Widget>[
            Row(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: <Widget>[
                Text(
                  "畅销爆品",
                  style: TextStyle(
                      color: Color(0xff040404),
                      fontSize: 21.0,
                      fontWeight: FontWeight.bold),
                ),
                Text(
                  "    火爆热卖中",
                  style: TextStyle(color: Color(0xffededed)),
                )
              ],
            ),
            SizedBox(
              height: 10.0,
            ),
            Image.asset("images/banner2.png", height: 100.0, fit: BoxFit.fill),
            Row(
              children: <Widget>[
                Expanded(
                    child: Container(
                  padding: EdgeInsets.all(10.0),
                  color: Color(0xffffffff),
                  height: 120.0,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Text(
                            "洗护套装",
                            style: TextStyle(fontSize: 18.0),
                          ),
                          Text(
                            "更健康",
                            style: TextStyle(color: Color(0xfff1f1f1)),
                          ),
                          Expanded(child: Text("")),
                          Row(
                            children: <Widget>[
                              Text(
                                "9",
                                style: TextStyle(
                                    color: Color(0xffe49f95), fontSize: 13.0),
                              ),
                              Text(
                                "9",
                                style: TextStyle(
                                    color: Color(0xfff1f1f1),
                                    fontSize: 13.0,
                                    decoration: TextDecoration.lineThrough,
                                    decorationColor: Color(0xfff1f1f1)),
                              )
                            ],
                          ),
                          Container(
                            padding: EdgeInsets.only(left: 5.0, right: 5.0),
                            child: Text(
                              "点击查看",
                              style: TextStyle(
                                  color: Color(0xffffffff), fontSize: 19.0),
                            ),
                            decoration: BoxDecoration(
                                gradient: LinearGradient(
                                    colors: [
                                      Color(0xFFf04d85),
                                      Color(0xFFfc9150)
                                    ],
                                    begin: FractionalOffset(0, 0),
                                    end: FractionalOffset(1, 1)),
                                borderRadius: BorderRadius.circular(15.0)),
                          )
                        ],
                      ),
                      Image.asset(
                        "images/ex3.png",
                        height: 90.0,
                        fit: BoxFit.fitHeight,
                      )
                    ],
                  ),
                )),
                Container(
                  height: 120.0,
                  width: 5.0,
                ),
                Expanded(
                    child: Container(
                  padding: EdgeInsets.all(10.0),
                  color: Color(0xffffffff),
                  height: 120.0,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Text(
                            "洗面奶",
                            style: TextStyle(fontSize: 18.0),
                          ),
                          Text(
                            "深度清洁",
                            style: TextStyle(color: Color(0xfff1f1f1)),
                          ),
                          Expanded(child: Text("")),
                          Row(
                            children: <Widget>[
                              Text(
                                "9",
                                style: TextStyle(
                                    color: Color(0xffe49f95), fontSize: 13.0),
                              ),
                              Text(
                                "9",
                                style: TextStyle(
                                    color: Color(0xfff1f1f1),
                                    fontSize: 13.0,
                                    decoration: TextDecoration.lineThrough,
                                    decorationColor: Color(0xfff1f1f1)),
                              )
                            ],
                          ),
                          Container(
                            padding: EdgeInsets.only(left: 5.0, right: 5.0),
                            child: Text(
                              "点击查看",
                              style: TextStyle(
                                  color: Color(0xffffffff), fontSize: 19.0),
                            ),
                            decoration: BoxDecoration(
                                gradient: LinearGradient(
                                    colors: [
                                      Color(0xFFf04d85),
                                      Color(0xFFfc9150)
                                    ],
                                    begin: FractionalOffset(0, 0),
                                    end: FractionalOffset(1, 1)),
                                borderRadius: BorderRadius.circular(15.0)),
                          )
                        ],
                      ),
                      Image.asset(
                        "images/ex4.png",
                        height: 90.0,
                        fit: BoxFit.fitHeight,
                      )
                    ],
                  ),
                ))
              ],
            )
          ],
        ));
  }

  Widget list() {
    return Container(
      margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 20.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          GestureDetector(
            child: Column(
              children: <Widget>[
                Text(
                  "推荐",
                  style: TextStyle(
                      fontSize: 20.0,
                      color: itemclicked == 0
                          ? Color(0xffe4c8ba)
                          : Color(0xff9b9b9b)),
                ),
                Container(
                  child: Text(
                    "为您定制",
                    style: TextStyle(
                        fontSize: 16.0,
                        color: itemclicked == 0
                            ? Color(0xffffffff)
                            : Color(0xffcccccc)),
                  ),
                  padding: EdgeInsets.only(left: 5.0, right: 5.0),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(15.0),
                      color: itemclicked == 0
                          ? Color(0xffc87552)
                          : Color(0x00000000)),
                )
              ],
            ),
            onTap: () {
              itemclicked = 0;
              setState(() {});
            },
          ),
          GestureDetector(
            child: Column(
              children: <Widget>[
                Text(
                  "美食",
                  style: TextStyle(
                      fontSize: 20.0,
                      color: itemclicked == 1
                          ? Color(0xffe4c8ba)
                          : Color(0xff9b9b9b)),
                ),
                Container(
                  child: Text("米面酒茶",
                      style: TextStyle(
                          fontSize: 16.0,
                          color: itemclicked == 1
                              ? Color(0xffffffff)
                              : Color(0xffcccccc))),
                  padding: EdgeInsets.only(left: 5.0, right: 5.0),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(15.0),
                      color: itemclicked == 1
                          ? Color(0xffc87552)
                          : Color(0x00000000)),
                )
              ],
            ),
            onTap: () {
              itemclicked = 1;
              setState(() {});
            },
          ),
          GestureDetector(
            child: Column(
              children: <Widget>[
                Text(
                  "日用",
                  style: TextStyle(
                      fontSize: 20.0,
                      color: itemclicked == 2
                          ? Color(0xffe4c8ba)
                          : Color(0xff9b9b9b)),
                ),
                Container(
                  child: Text("品质百货",
                      style: TextStyle(
                          fontSize: 16.0,
                          color: itemclicked == 2
                              ? Color(0xffffffff)
                              : Color(0xffcccccc))),
                  padding: EdgeInsets.only(left: 5.0, right: 5.0),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(15.0),
                      color: itemclicked == 2
                          ? Color(0xffc87552)
                          : Color(0x00000000)),
                )
              ],
            ),
            onTap: () {
              itemclicked = 2;
              setState(() {});
            },
          ),
          GestureDetector(
            child: Column(
              children: <Widget>[
                Text(
                  "全部",
                  style: TextStyle(
                      fontSize: 20.0,
                      color: itemclicked == 3
                          ? Color(0xffe4c8ba)
                          : Color(0xff9b9b9b)),
                ),
                Container(
                  child: Text("超多好货",
                      style: TextStyle(
                          fontSize: 16.0,
                          color: itemclicked == 3
                              ? Color(0xffffffff)
                              : Color(0xffcccccc))),
                  padding: EdgeInsets.only(left: 5.0, right: 5.0),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(15.0),
                      color: itemclicked == 3
                          ? Color(0xffc87552)
                          : Color(0x00000000)),
                )
              ],
            ),
            onTap: () {
              itemclicked = 3;
              setState(() {});
            },
          ),
        ],
      ),
    );
  }

  Widget listview() {
    return ListView.builder(
        itemCount: shoplist.length,
        itemBuilder: (_, index) {
          buildItem(_, index);
        });
  }

  Widget buildItem(context, index) {
    return GestureDetector(
      child: Column(
        children: <Widget>[
          SizedBox(height: 10.0,),
          Container(
              padding: EdgeInsets.all(10.0),
              margin: EdgeInsets.only(left: 10.0,right: 10.0),
              decoration: BoxDecoration(
                  color: Color(0xffffffff),
                  borderRadius: BorderRadius.circular(10.0)),
              child: Row(

                children: <Widget>[
                  Image.asset(shoplist[index].img,width: 60.0,height: 60.0,fit: BoxFit.cover,),
                  SizedBox(width: 10.0,),
                  Expanded(child:  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(shoplist[index].name,style: TextStyle(color: Color(0xff6e6e6e),fontSize: 19.0,fontWeight: FontWeight.bold),),
                      Container(
                        decoration: BoxDecoration(borderRadius: BorderRadius.circular(2.0),border: Border.all(color: Color(0xffe4c8ba),width: 1.0)),
                        child: Text(shoplist[index].range,style: TextStyle(color: Color(0xffe4c8ba),fontSize: 11.0),),
                      ),
                      Text(shoplist[index].address),
                      Text("记账${shoplist[index].cust}人",style: TextStyle(fontSize: 15.0,color:  Color(0xffe4c8ba)),)

                    ],
                  ))
                  ,
                  Container(
                    margin: EdgeInsets.only(right: 20.0),
                    child: Text(shoplist[index].dis),
                  )


                ],


              )


          ),

        ],
      ),
      onTap: (){
//        Fluttertoast.showToast(msg: shoplist[index].name);
        Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context){
          return new ShopDetail(shoplist[index]);
        }));
//        Navigator.pushReplacement(context, new MaterialPageRoute(builder: (context){
//          return new ShopDetail();
//        }));
      },
    );


  }

  void createlist() {
    shoplist = List();
    shoplist.add(Shop1(
        "DQ冰淇淋", "各种冰淇淋……", "北京市 东城区", "10km", "10", "images/bingqiling.jpg","朝阳区西大望21号合生汇商场五层507"));
    shoplist.add(
        Shop1("新屿悦和食汇", "日式料理……", "北京市 东城区", "1km", "11", "images/heshi.jpg","东城区王府井大街301号新燕莎金街购物广场6层"));
    shoplist.add(Shop1(
        "CAKEBOSS蛋糕老板", "蛋糕，甜食", "北京市 东城区", "11km", "12", "images/dangao.jpg","东城区王府井大街138号北京apm5层"));
    shoplist.add(Shop1(
        "反弹工厂蹦床公园", "蹦床，游戏", "北京市 东城区", "12km", "13", "images/bengchuang.jpg","朝阳区化工路5号垡头产业园泓彤体育院内"));
    shoplist.add(Shop1(
        "魔影国际影城", "好莱坞电影", "北京市 东城区", "13km", "14", "images/dianying.jpg","海淀区远大路1号院B座五楼西侧001号"));
    shoplist.add(
        Shop1("金真子纸上烤肉", "好吃的", "北京市 东城区", "14km", "15", "images/kaorou.jpg","朝阳区双桥地铁站北面北岸商业广场3楼"));
  }
}

void testisolate() {
  while (true) {
    print("iso");
  }
}
